package com.atguigu.singleton.type7;

/**
 * @author gcq
 * @Create 2020-09-30
 */
public class SingletonTest07 {
    public static void main(String[] args) {
        System.out.println("静态内部类");
        Singleton instance = Singleton.getInstance();
        Singleton instance1 = Singleton.getInstance();
        System.out.println(instance == instance1);
    }
}

// 静态内部类
class Singleton {
    private static volatile Singleton instance;

    private Singleton() {};
    // 写一个静态内部类 该类中有一个静态属性 Singleton
    private static class SingletonInstance {
        private static final Singleton INSTACE = new Singleton();
    }

    // 提供一个静态的公有方法，直接返回SingletonInstance.INSTANCE
    public static Singleton getInstance() {
        return SingletonInstance.INSTACE;
    }

}